import Cookie


class CookieClient(Cookie.SmartCookie):
    """
    Change the default behavior of the Cookie library in order to use it in web client
    The most obvious change is overwrite the method "output". After the overwrite, the method
    will output the string "Cookie:xxx" used in web client sent to web server
    """

    def output(self, header="Cookie: "):
        #specify the attrs aims output only the cookie key-value pairs
        #specify header equal space string in order to delete the set-cookie headers
        #specify sep equal '; ' in order to connect each cookie pairs to form a cookie string
        #append header (normally, it's "Cookie: ") to form a final cookie string

        return header + super(CookieClient, self).output(attrs='', header='', sep='; ')

def test():
    c = CookieClient("name=luocheng; email=luoc@nipc.org.cn")
    print c.output()

if __name__ == '__main__':
    test()